/**
 * Created by Administrator on 2017/6/5.
 */
app.controller('loginCtrl',function ($rootScope, $state, $scope, $http, $localStorage,storageService) {
    $scope.authError=false;
    $scope.login = function () {
        $http.get(API('huanbi/security/adminSignIn?account=')+$scope.loginName+'&password='+md5($scope.password)+'&openId='+$rootScope.openId).success(function (reslut) {
           if(reslut.successful){
               $rootScope.AdminInfo=reslut.data;
               storageService.setObject('AdminInfo',reslut.data);
               $state.go("home.table");
           }else {
               $scope.authError=true;
           }
        });
    };
})
app.controller('updateCtrl',function ($state, $scope, $http,$rootScope,dataService) {
    $scope.submit = function(){
        if($scope.data.newPasword !=$scope.data.confirmPassword){
            alert('两次密码不一致');
            return false;
        }
        var data ={
            'account':$rootScope.AdminInfo.account,
            'oldPassword':md5($scope.data.oldPassword),
            'newPasword':md5($scope.data.newPasword),
            'confirmPassword':md5($scope.data.confirmPassword)
        }
        $http.post(API('huanbi/staff/changePassword'),data).success(function (result) {
            if(result.successful){
                alert('密码修改成功');
                $state.go('login');
            }else {ta
                alert('密码修改失败');
            }
        })
    }
})